
#include <mockcpp/mockcpp.hpp>
#include <testngpp/testngpp.hpp>
#include <sstream>

#include <Length.h>
#include <Volume.h>

USING_MOCKCPP_NS
USING_TESTNGPP_NS

FIXTURE(Quantity)
{
        TEST(should be able to compare 1 feet with 12 inch)
        {
                Length feet(1, FEET);
                Length inch(12, INCH);

                ASSERT_EQ(true, feet==inch);
        }

        TEST(should be able to compare 1  yard with 3  feet)
        {
                Length yard(1, YARD);
                Length feet(3, FEET);

                ASSERT_EQ(true, feet==yard);
        }

        TEST(should be able to compare 1  mile with 1760  yard)
        {
                Length mile(1, MILE);
                Length yard(1760, YARD);

                ASSERT_EQ(true, mile==yard);
        }

        TEST(should be able to compare 1  feet with 12  inch)
        {
                Length feet(1, FEET);
                Length inch(12, INCH);
                Length feetAddCmp(2, FEET);

                ASSERT_EQ(true, feetAddCmp == feet + inch);
        }

        TEST(should be able to print 25 Inch as 0 Mile 0 Yard 2 Feet 1 Inch)
        {
                Length inch(25, INCH);
                Length mileAdd(0, MILE);
                Length yardAdd(0, YARD);
                Length feetAdd(2, FEET);
                Length inchAdd(1, INCH);

                ASSERT_EQ(true, inch == mileAdd + yardAdd + feetAdd + inchAdd);

                ostringstream lengthStream;
                string lengthString;
                string testString;

                lengthStream << inch;
                lengthString = lengthStream.str();
                testString = "0 MILE 0 YARD 2 FEET 1 INCH";
                ASSERT_EQ(true, lengthString == testString);
        }
        TEST(should be able to print 25 Inch as 25 Inch and also 0 Mile 0 Yard 2 Feet 1 Inch)
        {
                Length inch(25, INCH);

                ostringstream lengthStreamFormat;
                string lengthStringFormat;
                string testString;

                inch.output(lengthStreamFormat, LengthFormatorInStdFormat);
                lengthStringFormat = lengthStreamFormat.str();
                testString = "0 MILE 0 YARD 2 FEET 1 INCH";
                ASSERT_EQ(true, lengthStringFormat == testString);

                ostringstream lengthStreamInBaseUnit;
                string lengthStringInBaseUnit;

                testString.clear();
                inch.output(lengthStreamInBaseUnit, LengthFormatorInBaseUnit);
                lengthStringInBaseUnit = lengthStreamInBaseUnit.str();
                testString = "25 INCH";
                ASSERT_EQ(true, lengthStringInBaseUnit == testString);
        }

        TEST(should be able to compare 1 TBSP with 3 TSP)
        {
                Volume tbsp(1, TBSP);
                Volume tsp(3, TSP);

                ASSERT_EQ(true, tsp == tbsp);
        }

        TEST(should be able to print 28 TSP as 4 OZ 1 TBSP 1 TSP)
        {
                Volume tsp(28, TSP);
                Volume ozAdd(4, OZ);
                Volume tbspAdd(1, TBSP);
                Volume tspAdd(1, TSP);

                ASSERT_EQ(true, tsp == ozAdd + tbspAdd + tspAdd);

                ostringstream volumeStream;
                string volumeString;
                string testString;

                volumeStream << tsp;
                volumeString = volumeStream.str();
                testString = "4 OZ 1 TBSP 1 TSP";
                ASSERT_EQ(true, volumeString == testString);
        }

        TEST(should be able to print 28 TSP as 28 TSP and also 4 OZ 1 TBSP 1 TSP)
        {
                Volume tsp(28, TSP);

                ostringstream volumeStreamFormat;
                ostringstream volumeStreamInBaseUnit;
                string volumeStringFormat;
                string volumeStringInBaseUnit;
                string testString;

                tsp.output(volumeStreamFormat);
                volumeStringFormat = volumeStreamFormat.str();
                testString = "4 OZ 1 TBSP 1 TSP";
                ASSERT_EQ(true, volumeStringFormat == testString);

                testString.clear();
                tsp.output(volumeStreamInBaseUnit, VolumeFormatorInBaseUnit);
                volumeStringInBaseUnit = volumeStreamInBaseUnit.str();
                testString = "28 TSP";
                ASSERT_EQ(true, volumeStringInBaseUnit == testString);
        }
};

